package net.minecraft.src;

import java.util.List;

public class ContainerController extends Container
{
	/*
	class  TimeSection
	{

		private static int startXposition;
		private static int startYposition;
		public  TimeSection( int startXposition, int startYposition, TileSequenzer tileSequenzer )
		{
			for (int i = 0; i < 4; i++)
			{
			//	addSlot(new Slot(tileSequenzer , counter++, startXposition, startYposition + i * 18));
			}		
		}
	}
	
	class JumpSection
	{
		private int startXposition;
		private int startYposition;
		public  JumpSection( int startXposition, int startYposition, TileSequenzer tileSequenzer )
		{
			for (int l = 0; l < 4; l++)
			{
				//addSlot(new Slot(inTileSequenzer, counter++, 62 + l * 18, 17 + i * 18));
			}
		}
	}

	class InOutSection
	{
		private int startXposition;
		private int startYposition;

		public  InOutSection( int startXposition, int startYposition, TileSequenzer tileSequenzer )
		{
			for (int l = 0; l < 3; l++)
			{
				//addSlot(new Slot(inTileSequenzer, counter++, 62 + l * 18, 17 + i * 18));
			}
		}	
	}
	*/
	
	private static  int  freqStartX = 218;
	private static  int  freqStartY = 35;
	private static  int  inOutStartX = 18;
	private static  int  inOutStartY = 17 ;
	private static  int  jumpStartX = 101;
	private static  int  jumpStartY = 17;
	private static  int  inventoryStartX = 42;
	private static  int  inventoryStartY = 172;
	
	
	private static  int  commandRowNumber = 8;

	
	
	private static  int  freqRowNumber = 4;
	
	private static  int  jumpColumnNumber = 5;
	private static  int  inOutColumnNumber = 4;
	private static  int  inventoryNumber = 9;
	//int static 
	private TileController tileController;
	
	private static  int  sizeInPixels = 18;
	

    public ContainerController(IInventory iinventory, TileController inTileController)
    {
    	tileController = inTileController;
        int counter = 0;
        for (int i = 0; i < commandRowNumber; i++)
        {
            for (int l = 0; l < inOutColumnNumber; l++)
            {
                addSlot(new Slot(inTileController, counter++, inOutStartX + l * sizeInPixels, inOutStartY + i * sizeInPixels));
            }
  
            for (int l = 0; l < jumpColumnNumber; l++)
            {
                addSlot(new Slot(inTileController, counter++, jumpStartX + l*sizeInPixels, jumpStartY + i * sizeInPixels));
            }
        }

        for (int i = 0; i < freqRowNumber; i++)
        {
                addSlot(new Slot(inTileController, counter++, freqStartX, freqStartY + i * sizeInPixels));
        }

        for (int k = 0; k < inventoryNumber; k++)
        {
            addSlot(new Slot(iinventory, k, inventoryStartX + k * sizeInPixels, inventoryStartY));
        }
    }

    public boolean canInteractWith(EntityPlayer entityplayer)
    {
        return tileController.isUseableByPlayer(entityplayer);
    }

    public ItemStack transferStackInSlot(int i)
    {
        ItemStack itemstack = null;
        Slot slot = (Slot)inventorySlots.get(i);
        if (slot != null && slot.getHasStack())
        {
            ItemStack itemstack1 = slot.getStack();
            itemstack = itemstack1.copy();
            if (i < 9)
            {
                if (!mergeItemStack(itemstack1, 9, 45, true))
                {
                    return null;
                }
            }
            else if (!mergeItemStack(itemstack1, 0, 9, false))
            {
                return null;
            }
            if (itemstack1.stackSize == 0)
            {
                slot.putStack(null);
            }
            else
            {
                slot.onSlotChanged();
            }
            if (itemstack1.stackSize != itemstack.stackSize)
            {
                slot.onPickupFromSlot(itemstack1);
            }
            else
            {
                return null;
            }
        }
        return itemstack;
    }
}
